<template>
  <div class="outer-input" :style="{width:`${width}%`}">
    <div class="input-title">
        <span class="need" v-if="struc?.must">*</span>
        <span class="label-name">{{ struc?.viewName }}</span>
    </div>
    <div class="input-contextPackage">
      <el-input
        class="input-1"
        show-password
        v-model="valueInput.value"
        :placeholder="struc?.hint"
        @blur="out($event)"
        @change="change"
        @input="inputValue"
				:maxlength="struc?.length"
        
      ></el-input>
      <span class="errorhint" v-if="showError">{{
        struc?.errorHit
      }}</span>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted, PropType, ref, reactive, computed } from "vue";
import useDataCheck, { DataStruc } from "../../hook/datastruc";

export default defineComponent({
  type: 104,
  name: "TPassword",
  props: {
    struc: {
      type: Object as PropType<DataStruc>,
    },
    passWidth: {
			type: Number
		}
  },
  setup: (props, context) => {
    let showError = ref(false);
    let valueInput: DataStruc = reactive(props.struc as DataStruc);
    const dataCheck = useDataCheck();
    let check = () => {
      if (props.struc?.value) {
        showError.value = false;
  		} else {
        console.debug("检查出错：", showError);
        showError.value = true;
			}
			
      return !showError.value;
    };
    const change = () => {
      console.log("执行了");
    };

    const inputValue = (e: string) => {
			// console.debug("input事件触发", e)
      valueInput.value = e
    };
    const width = computed(() => props.passWidth)

    onMounted(() => {
      dataCheck.addDataCheck(check);
    });

    return { showError, check, change, inputValue, valueInput, width };
  },

  methods: {
    out(event: MouseEvent) {
      if(!this.valueInput.must) {
					this.showError = false;
				} else {
					this.check()
				}
    },
  },
});
</script>

<style scoped lang="scss">
@import '@style/extend';
.outer-input {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
  width: 33.333%;
  padding-right: 10px;
  box-sizing: border-box;
  .input-title {
    padding-bottom: 10px;
    color: $regularText;
    .need {
      color: red;
    }
    .label-name {
      font-size: $fontSize-1
    }
  
  }

  .input-contextPackage {
    .errorhint {
      @extend .error;
      height: 10px;
      display: block;
      line-height: 1;
    }
  }
}


</style>
